#include<bits/stdc++.h>
using namespace std;
int n,m;
int A[100001],c[100001],a[100001];
string d[21];
int main(){
    freopen("arena.in","r",stdin);
    freopen("arena.out","w",stdout);
    cin>>n>>m;
    for(int i=1;i<=n;++i) cin>>A[i];
    for(int i=1;i<=m;++i) cin>>c[i];
    int k=ceil(log2(n));
    for(int i=1;i<=k;++i) cin>>d[i];
    int t;
    cin>>t;
    while(t--){
        int x[4];
        for(int i=0;i<4;++i) cin>>x[i];
        for(int i=1;i<=n;++i){
            a[i]=A[i]^x[i%4];
        }
        cout<<1<<"\n";
    }
}